class AssignationsController < ApplicationController
	layout "assignations"

		before_filter :login_required
	
	active_scaffold :assignation do |config|
		config.list.columns = [:member,:position_label, :technology,:seniority,:team,:ovposition, :assignation_date,:backfill,:wave,:ovposition,:ovposition_position]
		config.create.columns = [:member,:position,:assignation_date,:ovposition]
                config.update.columns = [:finish_date]
                config.update.link.label = "De-Assign"
                config.actions.add :delete
                config.actions = [:list, :create,  :update, :delete, :search]
		config.columns[:position].form_ui = :select 
                #config.action_links.add 'deassign',:type=>:record,:label=>'Remove Assignation (w/history)',:parameters=>{id=>@id}
		config.columns[:member].form_ui = :select 
		config.columns[:ovposition].form_ui = :select 
		#config.columns[:position_backfill].ui_type = :select 
                config.list.per_page = 10
       		#config.columns[:technology].search_sql = "technologies.name"
		#config.columns[:team].search_sql = "teams.name"
		#config.columns[:ovposition].search_sql = "ovpositions.name"
		#config.columns[:wave].search_sql = "waves.name"
		#config.actions.add :export
		#config.export.columns = [:member,:position_label, :technology,:seniority,:team,:ovposition, :assignation_date,:backfill,:wave]
		#config.export.default_deselected_columns = [ :exename ]
		#config.export.default_delimiter = ';'
		#config.export.default_full_download = false
		#config.export.force_quotes = true 
		config.columns[:ovposition].label = "OneWorld Position Assig"
		#config.columns[:ovposition_position].label = "OW Position Position"
		#config.columns[:position_label].label = "Position Title"
	end
        def before_update_save(record)
          record.active = 0
        end
        def before_create_save(record)
          record.active = 1
        end
        
        def deassign
            assignation = Assignation.find(params[:id])
            assignation.active = 0
            assignation.finish_date = Time.now()
            #assignation.save()
            assignation.save!
            #the new assignation will be the open backfill of the old one
            #newassignation = Assignation.new
            #newassignation.position = assignation.position
            #newassignation.active = true
            redirect_to :action => 'list' 
        end
        def conditions_for_collection
            ['active = ?', [1]]
        end
        
        
        
end
